package com.bdyc.service.springImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.bdyc.controller.custom.PcategoryInfoPo;
import com.bdyc.dao.PcategoryInfoMapper;
import com.bdyc.service.spring.PcategoryInfoService;
@Service("pcategoryInfoService")
public class PcategoryInfoServiceImpl implements PcategoryInfoService {

	@Autowired(required=true)
	@Qualifier("pcategoryInfoMapper")
	private PcategoryInfoMapper pcategoryInfoMapper;

	public List<PcategoryInfoPo> findCategoryInfo(Map<String, Object> map) {
		//设置limit起始索引 (currentPage-1)*pageSize
				Integer currentPage = (Integer)map.get("page");
				Integer pageSize  = (Integer)map.get("rows");
				//封装查询记录数map
				Integer count = pcategoryInfoMapper.findPcategoryInfoListCount(map);
				if(count >0){
					Integer index = count/pageSize;
					System.out.println(count%pageSize);
					Integer sum = count%pageSize==0?index:index +1;
					if(currentPage == null || currentPage <= 0){
						currentPage =1;
					}
					if(currentPage > sum ){
						currentPage=sum ;
					}
					map.put("currentPage",  (currentPage-1)*pageSize);
					map.put("pageSize", pageSize);
				}
				return pcategoryInfoMapper.findPcategoryInfoList(map);
	}

	public Integer findCategoryInfoCount(Map<String, Object> sendMap) {
		return pcategoryInfoMapper.findPcategoryInfoListCount(sendMap);
	}

}
